package nio.file;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class FilesTest3 {

	public static void main(String[] args) throws InterruptedException {
		
		Path source = Path.of( "src/nio/file/FilesTest3.java" );
		Path target = Path.of( "nio" , "FilesTest3.java" );
		
		try {
			Files.copy(source, target , StandardCopyOption.REPLACE_EXISTING );
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		Thread.sleep( 10000 );
		
		Path filename = Path.of( "nio" , "FilesTest3.txt" );
		
		try {
			// Files.move( target , filename , StandardCopyOption.REPLACE_EXISTING );
			Files.move( target , filename , StandardCopyOption.ATOMIC_MOVE );
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		Thread.sleep( 10000 );
		
		try {
			// Files.delete( filename ); // 删除
			Files.deleteIfExists( filename ) ; // 存在即删除
		} catch (IOException e) {
			e.printStackTrace();
		} 
		
	}

}
